#include "basic.h"
#include "run.h"

// light web  oled motion 在run.h中已经实例化

void setup() {
  delay(1000);  // 系统稳定性等待
  Serial.begin(115200);

  if (!SPIFFS.begin()) {
    Serial.println("An error has occurred while mounting SPIFFS");
  } else {
    Serial.println("SPIFFS mounted successfully");

    Dir dir = SPIFFS.openDir("/");
    while (dir.next()) {
      Serial.println(dir.fileName());
    }
  }

  pinMode(CHARGING_ATTACH_PIN, INPUT);

  web.dnsServerInit();
 oled.init();
  //light.init();
  Serial.println("Initial Accomplished!");

  motion.reset();
  //delay(3000);
}

void loop() {
  current_time = millis();

happy();

   //Serial.println(current_time);
  // if (isCharging()) {
  //   Serial.println("Charging now I am sleeping");
  //   sleep();  // 直接休眠
  //   web.handleRequest();
  // } else if (web.getConnectUserNum() == 0)  // 判断是否有用户连接
  // {
  //   if (current_time - last_active_time > DELAY_AND_THEN_SLEEP)  // 等一等再休眠
  //   {
  //     Serial.println("Connect num =0");
  //     sleep();
  //   } else  // 在没有用户连接到睡眠的这一段时间内小狗停止运动
  //   {
  //     isMotionReset = false;
  //     run_code = STOP;
  //     webRun();//For test
  //   }
  // } else {
  //   last_active_time = current_time;
  //   webRun();
  // }
}